<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/6/30 0030
 * Time: 19:37
 */

namespace api\storage\model;


use think\Exception;
use think\Model;

class SmtMaterielModel extends Model
{
    protected $table = 'smt_materiel';
    protected  $uuid = 'uuid';

    /****
     * @param $where
     * @return false|\PDOStatement|string|\think\Collection
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException.Exception
     * 根据条件获取simulation（对应物料的模拟量）
     */
    function getSimulationNum($where){
        $result = $this->where($where)->select();
        return $result;
    }

    /***
     * @param $update
     * @param $where
     * @return void 更新Simulation的值
     *更新Simulation的值
     */
    public function updateSimulation($update,$where){
        $this->where($where)-> update($update);

    }

    /***
     * @param $where
     * 更新修改时间
     */
    public function updateCheckTime($where){
        $time = date("Y-m-d H:i:s",strtotime("now"));
        $this->where($where)-> update(['update_time' => $time]);

    }


    /***
     * @param $update
     * @param $where
     * @return SmtMaterielModel
     * 更新物料信息
     */
    public function updateMaterielWithLock($update, $where)
    {
        return $this->where($where)->update($update);
    }

    /***
     * @param $where
     * @param string $field
     * @return array|false|\PDOStatement|string|Model
     * @throws Exception
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     * 获取物料信息
     */
    public function findByLock($where,$field = '*'){
        $result = $this->where($where)->field($field)->lock(true)->find();
        return $result;
    }

    public function add($data){
        $result = $this->insert($data);
        return $result;
    }


}